package cm.example.shoppingplatformspringboot.mapper;

import cm.example.shoppingplatformspringboot.entity.Invoice;
import org.apache.ibatis.annotations.*;

@Mapper
public interface InvoiceMapper {
    // 创建发票
    @Insert("INSERT INTO wn_invoice (order_id, title, order_info, type, tax_id, bank_card, add_time) " +
            "VALUES (#{order_id}, #{title}, #{order_info}, #{type}, #{tax_id}, #{bank_card}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertInvoice(Invoice invoice);

    // 根据订单号查询发票
    @Select("SELECT * FROM wn_invoice WHERE order_id = #{order_id}")
    Invoice getInvoiceById(Integer order_id);

    // 根据订单ID修改发票信息（抬头、税号、银行卡）
    @Update("UPDATE wn_invoice SET title=#{title}, tax_id=#{tax_id}, bank_card=#{bank_card} WHERE order_id=#{order_id}")
    void updateInvoice(Invoice invoice);
}